package cn.wolfcode.book.dao.impl;

import cn.wolfcode.book.dao.BookDAO;
import cn.wolfcode.book.entity.Book;
import cn.wolfcode.book.entity.Books;
import cn.wolfcode.entity.BookQueryObject;
import cn.wolfcode.entity.QueryObject;
import cn.wolfcode.util.MyBaitUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author 李新雨的项目86176
 * @version 1.0
 * @date 2024-10-26 11:18
 */
public class BookDAOImpl implements BookDAO {

private SqlSession sqlSession=MyBaitUtils.getSSF();
    @Override
    public void add(Book book) {
        sqlSession.insert("cn.wolfcode.book.mapper.BookMapper.add",book);
        sqlSession.commit();

    }

    @Override
    public void delById(Long id) {
        sqlSession.delete("cn.wolfcode.book.mapper.BookMapper.deleteById",id);
        sqlSession.commit();

    }

    @Override
    public void edit(Book book) {
        sqlSession.update("cn.wolfcode.book.mapper.BookMapper.update",book);
        sqlSession.commit();
    }

    @Override
    public Book selOneById(Long id) {
        return sqlSession.selectOne("cn.wolfcode.book.mapper.BookMapper.getById",id);
    }

    @Override
    public List<Book> selAll() {
        return sqlSession.selectList("cn.wolfcode.book.mapper.BookMapper.selAll");
    }



    /**
     * 根据条件查询
     * 动态sql的使用
     * @param bookQueryObject
     * @return
     */
    @Override
    public List<Book> selConditionAll(BookQueryObject bookQueryObject) {
        return sqlSession.selectList("cn.wolfcode.book.mapper.BookMapper.selConditionAll",bookQueryObject);
    }




    @Override
    public int selCount(QueryObject qo) {
        return sqlSession.selectOne("cn.wolfcode.book.mapper.BookMapper.selCount",qo);
    }

    @Override
    public List<Book> selList(QueryObject qo) {
        return sqlSession.selectList("cn.wolfcode.book.mapper.BookMapper.selList",qo);
    }

    @Override
    public List<Book> selAllTrue(QueryObject queryObject) {
        return sqlSession.selectList("cn.wolfcode.book.mapper.BookMapper.selTrue",queryObject);
    }

    @Override
    public void addT(Books book) {
        sqlSession.insert("cn.wolfcode.book.mapper.BookMapper.addT",book);
        sqlSession.commit();

    }
}
